<?php if ( ! defined('DIR')) exit('No direct script access allowed');

	class Load{
	
		public $loaded_module = array();
		
		public $loaded_lib = array();
				
		public function module($module){
			if(in_array($module,$this->loaded_module)){
				return;
			}
			if(file_exists(DIR."/Module/".$module.".class.php")){
				require(DIR."/Module/".$module.".class.php");
				$Control = getInstance();
				$Control->$module = new $module();
				$this->loaded_module[$module]=$module;
			}
		}	
		
		public function Lib($Lib){
			if(in_array($Lib,$this->loaded_lib)){
				return;
			}
			if(file_exists(DIR."/Lib/".$Lib.".class.php")){
				@require(DIR."/Module/".$Lib.".class.php");
				$Control = getInstance();
				$Control->$Lib = new $Lib();
				$this->loaded_lib[$Lib]=$Lib;
			}
		}	
		
		public function autoload(){
			foreach(getConfig('Modules') as $value){
				
				if(in_array($value,$this->loaded_module))
					continue;
					
				if(file_exists(DIR."/Module/".$value.".class.php")){
					@require(DIR."/Module/".$value.".class.php");
					$Control = getInstance();
					$Control->$value = new $value();
					$this->loaded_module[$value]=$value;
				}
			}
			foreach(getConfig('Libs') as $value){
			
				if(in_array($value,$this->loaded_lib))
					continue;
					
				if(file_exists(DIR."/Lib/".$value.".class.php")){
					@require(DIR."/Lib/".$value.".class.php");
					$Control = getInstance();
					$Control->$value = new $value();
					$this->loaded_lib[$value]=$value;
				}	
			}
		}	
		
		public function show($view,$args=null){
			if(file_exists(DIR."/Tpl/".$view.".php")){
				if(is_array($args))
					extract($args);
				@require(DIR."/Tpl/".$view.".php");
			}
		}
		
	}	